Passed
Push — add-failing-tests ( 3ed854 )
by Eric
01:20
created

describe(ꞌutilities.inheritsꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 56
rs 9.7251

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var utilities = require('../utilities.js');
2
3
describe('utilities.inherits', function() {
4
    describe('failing tests', function() {
5
        // test example from README.md
6
        var SuperClass = {};
0 ignored issues
show
Unused Code introduced by
The variable SuperClass seems to be never used. Consider removing it.
Loading history...
7
8
        // a class we want to inherit from SuperClass
9
        var SomeClass = function() {};
10
11
        it("should fail because the Constructor is undefined", function() {
12
            expect(utilities.inherits.bind()).toThrowError(TypeError);
13
        });
14
15
        it("should fail because the Constructor is null", function() {
16
            expect(utilities.inherits.bind(null, null)).toThrowError(TypeError);
17
        });
18
19
        it("should fail because the SuperConstructor is undefined", function() {
20
            expect(utilities.inherits.bind(null, SomeClass)).toThrowError(TypeError);
21
        });
22
23
        it("should fail because the SuperConstructor is null", function() {
24
            expect(utilities.inherits.bind(null, SomeClass, null)).toThrowError(TypeError);
25
        });
26
27
        it("should fail because the SuperConstructor has no prototype", function() {
28
            expect(utilities.inherits.bind(null, SomeClass, [])).toThrowError(TypeError);
29
        });
30
    });
31
    describe('successful tests', function() {
32
        // test example from README.md
33
        var SuperClass = function() {
34
            this.someProperty = 42;
35
        };
36
37
        SuperClass.prototype.retMsg = function(msg) {
38
            return msg;
39
        };
40
41
        SuperClass.prototype.getSomeProp = function() {
42
            return this.someProperty;
43
        };
44
45
        // a class we want to inherit from SuperClass
46
        var SomeClass = function() {
47
            SuperClass.call(this);
48
        };
49
50
        utilities.inherits(SomeClass, SuperClass);
51
52
        SomeClass.prototype.flop = function(msg) {
53
            return this.retMsg(msg);
54
        };
55
56
        var someClass_instance = new SomeClass();
57
        // end test example from README.md
58
59
        it("should be able to access inherited properties", function() {
60
            expect(someClass_instance.someProperty).toEqual(42);
61
        });
62
63
        it("should be able to run inherited methods", function() {
64
            expect(someClass_instance.retMsg('hi')).toEqual('hi');
65
        });
66
67
        it("should be able to run inherited methods by using the this keyword", function() {
68
            expect(someClass_instance.flop('hi')).toEqual('hi');
69
        });
70
71
        it("should be instance of SomeClass", function() {
72
            expect((someClass_instance instanceof SomeClass)).toEqual(true);
73
        });
74
75
        it("should be instance of SuperClass", function() {
76
            expect((someClass_instance instanceof SuperClass)).toEqual(true);
77
        });
78
79
        it("should set SuperClass contructor", function() {
80
            expect(someClass_instance.constructor.super_ === SuperClass).toEqual(true);
81
        });
82
83
        it("should set contructor", function() {
84
            expect(someClass_instance.constructor === SomeClass).toEqual(true);
85
        });
86
    });
87
});